<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>添加或编辑角色</title>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/resources/css/style.css" />
<script src="<%=request.getContextPath()%>/resources/js/jquery.js"></script>
<script src="<%=request.getContextPath()%>/resources/js/jquery.mCustomScrollbar.concat.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/resources/js/jquery.validate.js"></script>
<script>
	$(function(){
		
		//回显
		var authorities = '${role.authorities}';
		$("input[name='authorities']").each(function(){
			var value = $(this).val();
			if(authorities.indexOf(value) >= 0){
				$(this).attr("checked",true);
			}
		});
		
		
		$("#form").validate({
			rules: {
				name: "required"
			},
			messages: {
				
			},
            submitHandler: function (form) {
            	$.ajax({//验证新增是否成功
	 				type : "post",
	 				dataType:"json",
	 				url: "${empty role?'save':'update' }.do",
	 				data: $("form").serialize(),
	 				success : function(data) {
	 					if (data) {
	 						layer.msg('操作成功！');
	 					} else {
	 						layer.msg('操作失败！');
	 					}
	 				}
	 			});
            }
		});
		
		$("#submit").click(function(){
			$("#form").submit();
		});
	});
</script>
</head>
<body>
	<!--header-->
	<jsp:include page="../common/header.jsp"></jsp:include>
	
	<section>
		<div class="rt_content">
			<p>&nbsp;</p>
			<div class="page_title">
				<a class="fr top_rt_btn" id="submit">保存</a>
			</div>
			
			<div class="pop_cont_input">
				<form id="form" method="post">
					<input type="hidden" name="id" value="${role.id }">
					<table class="table">
						<tr>
							<th>
								名称: 
							</th>
							<td>
								<input type="text"  name="name" size="30" value="${role.name }"/>
							</td>
						</tr>
						<tr>
							<th>
								描述: 
							</th>
							<td>
								<input type="text"  name="description" size="30" value="${role.description }"/>
							</td>
						</tr>
						
						<!-- 订单管理 -->
						<tr class="authorities">
							<th>
								订单管理
							</th>
							<td>
								<span class="fieldSet">
									<label>
										<input type="checkbox" name="authorities" value="order:list"/>订单列表
									</label>
									<label>
										<input type="checkbox" name="authorities" value="order:save"/>添加订单
									</label>
									<label>
										<input type="checkbox" name="authorities" value="order:update" />编辑订单
									</label>
									<label>
										<input type="checkbox" name="authorities" value="order:delete" />删除订单
									</label>
									<label>
										<input type="checkbox" name="authorities" value="order:upload" />导入订单
									</label>
									<label>
										<input type="checkbox" name="authorities" value="order:download" />导出订单
									</label>
								</span>
							</td>
						</tr>
						<!-- 管理员管理 -->
						<tr class="authorities">
							<th>
								角色管理
							</th>
							<td>
								<span class="fieldSet">
									<label>
										<input type="checkbox" name="authorities" value="admin:list"/>管理员列表
									</label>
									<label>
										<input type="checkbox" name="authorities" value="admin:save"/>添加管理员
									</label>
									<label>
										<input type="checkbox" name="authorities" value="admin:update" />编辑管理员
									</label>
									<label>
										<input type="checkbox" name="authorities" value="admin:delete" />删除管理员
									</label>
								</span>
							</td>
						</tr>
						<!-- 角色管理 -->
						<tr class="authorities">
							<th>
								角色管理
							</th>
							<td>
								<span class="fieldSet">
									<label>
										<input type="checkbox" name="authorities" value="role:list"/>权限列表
									</label>
									<label>
										<input type="checkbox" name="authorities" value="role:save"/>添加权限
									</label>
									<label>
										<input type="checkbox" name="authorities" value="role:update" />编辑权限
									</label>
									<label>
										<input type="checkbox" name="authorities" value="role:delete" />删除权限
									</label>
								</span>
							</td>
						</tr>
						
						<!-- 日志管理 -->
						<tr class="authorities">
							<th>
								日志管理
							</th>
							<td>
								<span class="fieldSet">
									<label>
										<input type="checkbox" name="authorities" value="log:list"/>日志列表
									</label>
									<label>
										<input type="checkbox" name="authorities" value="log:delete" />删除日志
									</label>
								</span>
							</td>
						</tr>
					</table>
				</form>
			</div>
		</div>
	</section>
</body>
</html>

